/*
 * SyncronizerAsteroides.cpp
 *
 *  Created on: Jul 3, 2012
 *      Author: gonzalo
 */

#include "SyncronizerAsteroides.h"
#include "../common/utils/GameUtils.h"
#include "../common/DTOAsteroide.h"


SyncronizerAsteroides::SyncronizerAsteroides(PlayScenarioPanel* container,Client* client) {
	this->container = container;
	this->client = client;
	quering = true;
}

void SyncronizerAsteroides::query(){
	//random = GameUtils::getRandIntValueInRange(container->getUltimoIdAsteroideConst());
	random++;

	if(random > container->getUltimoIdAsteroideConst()) random = 0;

	container->setSyncroQueringId(random);
}

void SyncronizerAsteroides::syncro(){

	Asteroide* asteroide = container->getSyncroResult();

	if(!asteroide) return;

	DTOAsteroide* dto = asteroide->getDTO(container->getOwner());
	dto->actionRequired = UPDATE;

	client->setMensaje(dto);
}

bool SyncronizerAsteroides::isQuering() const
{
    return quering;
}

void SyncronizerAsteroides::operate(){
	if(quering){
		quering = !quering;
		return query();
	}else{
		quering = !quering;
		return syncro();
	}


}
